from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm, TextInput
from django.template.loader import render_to_string
import datetime
import settings

class DateJQueryWidget(TextInput):
	def __init__(self, attrs=None):
		TextInput.__init__(self, attrs)
		
	class Media:
		js = ('%sjs/widgets_script33.js' % settings.STATIC_URL,)
		css = {
			'all': ()
		}
		
	def render(self, name, value=None, attrs=None):
		return render_to_string('date-jquery-widget.html', { 
			'name': name,
			'value': value,
			'attrs': attrs
		})
		

class UserProfile(models.Model):
	user = models.ForeignKey(User, unique=True)
	name =  models.CharField(max_length=50, blank=True)
	surname =  models.CharField(max_length=50, blank=True)
	bio =  models.CharField(max_length=50, blank=True)
	birthday =  models.DateField()
	contact = models.TextField(blank=True)
	
class UserProfileForm(ModelForm):
	class Media:
		js = ('%sjs/widgets_script.js' % settings.STATIC_URL,)
		css = {
			'all': ()
		}
	class Meta:
		model = UserProfile
		widgets = {
			'birthday': DateJQueryWidget(),
		}
	
		
		
